#ifndef LEETCODE_CN_CPP_PROBLEMS_500_H
#define LEETCODE_CN_CPP_PROBLEMS_500_H

#include <algorithm>
#include <functional>
#include <string>
#include <vector>

using namespace std;

namespace problem_500
{

class Solution
{
private:
    const string row3 = "eiopqrtuwy";
    const string row2 = "adfghjkls";
    const string row1 = "bcmnvxz";

public:
    vector<string> findWords(vector<string> &words)
    {
        vector<string> result;
        for (auto &word : words)
        {
            result.push_back(word);
            transform(word.begin(), word.end(), word.begin(),
                      [](unsigned char c) -> unsigned char { return tolower(c); });
            sort(word.begin(), word.end());
            auto last = unique(word.begin(), word.end());
            if (!(includes(row3.begin(), row3.end(), word.begin(), last) ||
                  includes(row2.begin(), row2.end(), word.begin(), last) ||
                  includes(row1.begin(), row1.end(), word.begin(), last)))
                result.pop_back();
        }
        return result;
    }
};

} // namespace problem_500

#endif //LEETCODE_CN_CPP_PROBLEMS_500_H
